package com.lagou.work1

import org.apache.flink.api.scala._

object WordCountScalaBatch {
  def main(args: Array[String]): Unit = {
    //定义输入输出
    val in = "src/main/scala/com/lagou/work1/wc.txt"
    val out = "src/main/scala/com/lagou/work1/out"

    //获取flink 执行环境
    val env: ExecutionEnvironment = ExecutionEnvironment.getExecutionEnvironment
    //获取数据内容
    val text: DataSet[String] = env.readTextFile(in)
    //对数据进行切分、拼接、聚合、累加处理
    val data: AggregateDataSet[(String, Int)] = text.flatMap(_.split(" "))
      .map((_, 1))
      .groupBy(0)
      .sum(1)
    //保存输出结果
    data.writeAsText(out).setParallelism(1)
    data.print()

  }
}
